<template>
  <ma-form-modal ref="addMoneyRef" :columns="columns" title="余额充值" :submit="submit" v-if='type'>

  </ma-form-modal>
</template>

<script setup>
import MaFormModal from "@/components/ma-form-modal/index.vue"
import {ref} from "vue";
import dept from "@/api/system/dept";
import apiFinancialMoneyLog from "@/api/financial/financialMoneyLog";
import {Message} from "@arco-design/web-vue";
const type = ref()
const modalShow = ref(false)
const columns = ref([
  {
    title: "客户公司",
    dataIndex: "dept_id",
    formType: "select",
    disabled:false,
    dict: {
      // 远程通用接口请求，新版代码生成都有一个 remote 接口
      remote: "system/dept/remote",
      // 指定组件接收的props
      props: { label: "name", value: "id" },
      // 开启分页
      openPage: false,
      // 远程请求配置项
      remoteOption: {
        // 按用户名排序
        sort: { id: "desc" }, // 如果不指定排序方式，默认为正序排序
        // 设置查询的字段
        select: ["id", "name"],
        // 设置数据过滤
        filter: {
          type: ["=", 2],
          status: ['=',1]
        },
        // 关联模型
        relations: [],
      },
    },
    rules: {
      required: true,
      message: "请选择充值公司"
    }
  },
  {
    title: "充值金额",
    dataIndex: "price",
    formType: "input",
    search: true,
    min: 0,
    rules: {
      required: true,
      message: "请输入充值金额"
    }
  },
  {
    title: "上传凭证",
    dataIndex: "transfer_proof_images",
    formType: "upload",
    type: "image",
    returnType: "url",
    multiple: true,
    onlyUrl: true,
  },
  {
    title: "备注",
    dataIndex: "notes",
    formType:"textarea"
  }
])
const addMoneyRef = ref()

const submit = async (data) => {
  // if(data.transfer_proof_images){
  //   return Message.error('请上传支付凭证')
  // }
  if(data.transfer_proof_images){
    data.transfer_proof_images = data.transfer_proof_images.join(',')
  }else{
    data.transfer_proof_images = ''
  }
  let res = await apiFinancialMoneyLog.nowSave({
    ...data,
  })
  if (res.success) {
    Message.success(res.message)
    callbackFunction(res)
    return true
  }
  return false
}
var callbackFunction = null
defineExpose({
  open(data, callback){
    this.callback(callback)
    modalShow.value = true
    type.value = data.type
    setTimeout(() => {
      if(data.type == 1){
        addMoneyRef.value.open({type:2 })
      }else{
        addMoneyRef.value.open({type:2,dept_id:data.dept_id })
      }
    }, 50);
    
  },
  callback(callback){
    callbackFunction = callback
  }
})
</script>

<style scoped>

</style>
